<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        (function () {
            // this
            // 1.作为对象的方法调用
            window.alert = function (res) {
                console.log(res)
            }
            var obj = {
                a: 1,
                getA() {
                    alert(this === obj)
                    alert(this.a)
                }
            }
            obj.getA()

            // 2.作为普通函数调用
            window.name = 'globalName';
            var getName = function () {
                return this.name;
            }
            console.log(getName());
            // 或者：
            window.name = 'globalName';
            var myObject = {
                name: 'sven',
                getName: function () { return this.name }
            }
            var getName = myObject.getName;
            console.log(getName());

            

        })()
    </script>
</body>

</html>